﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.IdentityModel.Claims;
using System.Web.UI.WebControls;
using Veracruz.IdentityModel;

namespace Veracruz.Facebook.Sharepoint.Webparts
{
    public sealed class DisplayRoles
        :WebPart
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Title = "Display roles";
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (ClaimsPrincipal.Current.Identities.Count > 0)
            {
                IClaimsIdentity __claimsIdentity = ClaimsPrincipal.Current.Identities[0];
                List<Claim> __roleClaims = new List<Claim>(__claimsIdentity.Claims.FindAll(c => c.ClaimType == RoleClaimDefinitions.ClaimType));
                foreach (var item in __roleClaims)
                {
                    Label __claimLbl = new Label();
                    __claimLbl.Text = item.Value;
                    __claimLbl.RenderControl(writer);

                    writer.WriteLine("<br />");
                }
            }
            else
            {
                Label __noClaims = new Label();
                __noClaims.Text = "No roles to display please signin";
                __noClaims.RenderControl(writer);
            }

            base.Render(writer);
        }
    }
}
